﻿// CSettingDlg.cpp: 实现文件
//

#include "pch.h"
#include "SP.h"
#include "CSettingDlg.h"
#include "afxdialogex.h"
#include "SP.h"

// CSettingDlg 对话框

IMPLEMENT_DYNAMIC(CSettingDlg, CDialogEx)

CSettingDlg::CSettingDlg(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_DLG_SETTING, pParent)
	, nPosX0(0)
	, nPosX1(0)
	, nPosX2(0)
	, nPosX3(0)
	, nPosX4(0)
	, nPosX5(0)
	, nPosX6(0)
	, nPosX8(0)
	, nPosY0(0)
	, nPosY1(0)
	, nPosY2(0)
	, nPosY3(0)
	, nPosY4(0)
	, nPosY5(0)
	, nPosY6(0)
	, nPosY8(0)
	, nPosZ0(0)
	, nPosZ1(0)
	, nPosZ2(0)
	, nPosZ3(0)
	, nPosZ4(0)
	, nPosZ5(0)
	, nPosZ6(0)
	, nPosZ8(0)
	, bFlag0(FALSE)
	, bFlag1(FALSE)
	, bFlag2(FALSE)
	, bFlag3(FALSE)
	, bFlag4(FALSE)
	, bFlag5(FALSE)
	, PosX8(0)
	, PosY8(0)
	, PosZ8(0)
	, m_nPitouMax(0)
{

}

CSettingDlg::~CSettingDlg()
{
}

void CSettingDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Text(pDX, IDC_EDIT_POSX1, nPosX0);
	DDX_Text(pDX, IDC_EDIT_POSX2, nPosX1);
	DDX_Text(pDX, IDC_EDIT_POSX3, nPosX2);
	DDX_Text(pDX, IDC_EDIT_POSX4, nPosX3);
	DDX_Text(pDX, IDC_EDIT_POSX5, nPosX4);
	DDX_Text(pDX, IDC_EDIT_POSX6, nPosX5);
	DDX_Text(pDX, IDC_EDIT_POSX7, nPosX6);

	DDX_Text(pDX, IDC_EDIT_POSX9, nPosX8);
	DDX_Text(pDX, IDC_EDIT_POSY1, nPosY0);
	DDX_Text(pDX, IDC_EDIT_POSY2, nPosY1);
	DDX_Text(pDX, IDC_EDIT_POSY3, nPosY2);
	DDX_Text(pDX, IDC_EDIT_POSY4, nPosY3);
	DDX_Text(pDX, IDC_EDIT_POSY5, nPosY4);
	DDX_Text(pDX, IDC_EDIT_POSY6, nPosY5);
	DDX_Text(pDX, IDC_EDIT_POSY7, nPosY6);

	DDX_Text(pDX, IDC_EDIT_POSY9, nPosY8);
	DDX_Text(pDX, IDC_EDIT_POSZ1, nPosZ0);
	DDX_Text(pDX, IDC_EDIT_POSZ2, nPosZ1);
	DDX_Text(pDX, IDC_EDIT_POSZ3, nPosZ2);
	DDX_Text(pDX, IDC_EDIT_POSZ4, nPosZ3);
	DDX_Text(pDX, IDC_EDIT_POSZ5, nPosZ4);
	DDX_Text(pDX, IDC_EDIT_POSZ6, nPosZ5);
	DDX_Text(pDX, IDC_EDIT_POSZ7, nPosZ6);

	DDX_Text(pDX, IDC_EDIT_POSZ9, nPosZ8);
	DDX_Check(pDX, IDC_CHECK_FLAG1, bFlag0);
	DDX_Check(pDX, IDC_CHECK_FLAG2, bFlag1);
	DDX_Check(pDX, IDC_CHECK_FLAG3, bFlag2);
	DDX_Check(pDX, IDC_CHECK_FLAG4, bFlag3);
	DDX_Check(pDX, IDC_CHECK_FLAG5, bFlag4);
	DDX_Check(pDX, IDC_CHECK_FLAG6, bFlag5);


	DDX_Text(pDX, IDC_EDIT_PX8, PosX8);
	DDX_Text(pDX, IDC_EDIT_PY8, PosY8);
	DDX_Text(pDX, IDC_EDIT_PZ8, PosZ8);
	DDX_Text(pDX, IDC_EDIT1, m_nPitouMax);
	DDX_Control(pDX, IDC_COMBO1, m_comboTaskNum);
}

BOOL CSettingDlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();
	ReadConfig();
	m_comboTaskNum.ResetContent();
	for ( int i = 1; i <= 12; ++i) {
		CString str;

		str.Format(L"%02d: 任务%02d", i, i);
		m_comboTaskNum.AddString(str);
	}
	m_comboTaskNum.SetCurSel(Manager.m_nTaskSelect);


	return TRUE;
}


BEGIN_MESSAGE_MAP(CSettingDlg, CDialogEx)
	ON_BN_CLICKED(IDC_BTN_SAVE, &CSettingDlg::OnBnClickedBtnSave)
	ON_BN_CLICKED(IDC_SETDATA, &CSettingDlg::OnBnClickedSetdata)
	ON_BN_CLICKED(IDC_SETDATA2, &CSettingDlg::OnBnClickedSetdata2)
	ON_BN_CLICKED(IDC_SETDATA3, &CSettingDlg::OnBnClickedSetdata3)
	ON_BN_CLICKED(IDC_SETDATA4, &CSettingDlg::OnBnClickedSetdata4)
	ON_BN_CLICKED(IDC_SETDATA5, &CSettingDlg::OnBnClickedSetdata5)
	ON_BN_CLICKED(IDC_SETDATA6, &CSettingDlg::OnBnClickedSetdata6)

	ON_BN_CLICKED(IDC_SETDATA9, &CSettingDlg::OnBnClickedSetdata9)
	ON_BN_CLICKED(IDC_SETDATA10, &CSettingDlg::OnBnClickedSetdata10)
	ON_EN_CHANGE(IDC_EDIT1, &CSettingDlg::OnEnChangeEdit1)
END_MESSAGE_MAP()


// CSettingDlg 消息处理程序


void CSettingDlg::OnBnClickedBtnSave()
{
	// TODO: 在此添加控件通知处理程序代码
	SaveEditToConfig();
}

void CSettingDlg::ReadConfig()
{
	nPosX0 = Manager.m_nPosX[0];
	nPosX1 = Manager.m_nPosX[1];
	nPosX2 = Manager.m_nPosX[2];
	nPosX3 = Manager.m_nPosX[3];
	nPosX4 = Manager.m_nPosX[4];
	nPosX5 = Manager.m_nPosX[5];
	nPosX6 = Manager.m_nPosX[6];
	PosX8= Manager.m_nPosX[7];
	nPosX8 = Manager.m_nPosX[8];

	nPosY0 = Manager.m_nPosY[0];
	nPosY1 = Manager.m_nPosY[1];
	nPosY2 = Manager.m_nPosY[2];
	nPosY3 = Manager.m_nPosY[3];
	nPosY4 = Manager.m_nPosY[4];
	nPosY5 = Manager.m_nPosY[5];
	nPosY6 = Manager.m_nPosY[6];
	PosY8 = Manager.m_nPosY[7];
	nPosY8 = Manager.m_nPosY[8];

	nPosZ0 = Manager.m_nPosZ[0];
	nPosZ1 = Manager.m_nPosZ[1];
	nPosZ2 = Manager.m_nPosZ[2];
	nPosZ3 = Manager.m_nPosZ[3];
	nPosZ4 = Manager.m_nPosZ[4];
	nPosZ5 = Manager.m_nPosZ[5];
	nPosZ6 = Manager.m_nPosZ[6];
	PosZ8 = Manager.m_nPosZ[7];
	nPosZ8 = Manager.m_nPosZ[8];

	bFlag0 = Manager.m_nLockFlag[0];
	bFlag1 = Manager.m_nLockFlag[1];
	bFlag2 = Manager.m_nLockFlag[2];
	bFlag3 = Manager.m_nLockFlag[3];
	bFlag4 = Manager.m_nLockFlag[4];
	bFlag5 = Manager.m_nLockFlag[5];

	m_nPitouMax = Manager.m_nPitouMax;
	UpdateData(FALSE);
}

void CSettingDlg::SaveEditToConfig()
{
	UpdateData(TRUE);
	Manager.m_nTaskSelect = m_comboTaskNum.GetCurSel();

	Manager.m_nPosX[0] = nPosX0;
	Manager.m_nPosX[1] = nPosX1;
	Manager.m_nPosX[2] = nPosX2;
	Manager.m_nPosX[3] = nPosX3;
	Manager.m_nPosX[4] = nPosX4;
	Manager.m_nPosX[5] = nPosX5;
	Manager.m_nPosX[6] = nPosX6;
	Manager.m_nPosX[7] = PosX8;
	Manager.m_nPosX[8] = nPosX8;

	Manager.m_nPosY[0] = nPosY0;
	Manager.m_nPosY[1] = nPosY1;
	Manager.m_nPosY[2] = nPosY2;
	Manager.m_nPosY[3] = nPosY3;
	Manager.m_nPosY[4] = nPosY4;
	Manager.m_nPosY[5] = nPosY5;
	Manager.m_nPosY[6] = nPosY6;
	Manager.m_nPosY[7] = PosY8;
	Manager.m_nPosY[8] = nPosY8;

	Manager.m_nPosZ[0] = nPosZ0;
	Manager.m_nPosZ[1] = nPosZ1;
	Manager.m_nPosZ[2] = nPosZ2;
	Manager.m_nPosZ[3] = nPosZ3;
	Manager.m_nPosZ[4] = nPosZ4;
	Manager.m_nPosZ[5] = nPosZ5;
	Manager.m_nPosZ[6] = nPosZ6;
	Manager.m_nPosZ[7] = PosZ8;
	Manager.m_nPosZ[8] = nPosZ8;

	Manager.m_nLockFlag[0] = bFlag0;
	Manager.m_nLockFlag[1] = bFlag1;
	Manager.m_nLockFlag[2] = bFlag2;
	Manager.m_nLockFlag[3] = bFlag3;
	Manager.m_nLockFlag[4] = bFlag4;
	Manager.m_nLockFlag[5] = bFlag5;

	Manager.m_nPitouMax=m_nPitouMax;

	CString str;

	str.Format(L"%d", Manager.m_nTaskSelect);
	Manager.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_nTaskSelect", str);

	str.Format(L"%d",Manager.m_nPosX[0]);
	Manager.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_nPosX[0]", str);
	str.Format(L"%d", Manager.m_nPosX[1]);
	Manager.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_nPosX[1]", str);
	str.Format(L"%d", Manager.m_nPosX[2]);
	Manager.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_nPosX[2]", str);
	str.Format(L"%d", Manager.m_nPosX[3]);
	Manager.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_nPosX[3]", str);
	str.Format(L"%d", Manager.m_nPosX[4]);
	Manager.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_nPosX[4]", str);
	str.Format(L"%d", Manager.m_nPosX[5]);
	Manager.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_nPosX[5]", str);
	str.Format(L"%d", Manager.m_nPosX[6]);
	Manager.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_nPosX[6]", str);
	str.Format(L"%d", Manager.m_nPosX[7]);
	Manager.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_nPosX[7]", str);
	str.Format(L"%d", Manager.m_nPosX[8]);
	Manager.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_nPosX[8]", str);
	str.Format(L"%d", Manager.m_nPosX[9]);
	Manager.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_nPosX[9]", str);

	str.Format(L"%d", Manager.m_nPitouMax);
	Manager.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_nPitouMax", str);


	str.Format(L"%d", Manager.m_nPosY[0]);
	Manager.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_nPosY[0]", str);
	str.Format(L"%d", Manager.m_nPosY[1]);
	Manager.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_nPosY[1]", str);
	str.Format(L"%d", Manager.m_nPosY[2]);
	Manager.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_nPosY[2]", str);
	str.Format(L"%d", Manager.m_nPosY[3]);
	Manager.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_nPosY[3]", str);
	str.Format(L"%d", Manager.m_nPosY[4]);
	Manager.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_nPosY[4]", str);
	str.Format(L"%d", Manager.m_nPosY[5]);
	Manager.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_nPosY[5]", str);
	str.Format(L"%d", Manager.m_nPosY[6]);
	Manager.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_nPosY[6]", str);
	str.Format(L"%d", Manager.m_nPosY[7]);
	Manager.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_nPosY[7]", str);
	str.Format(L"%d", Manager.m_nPosY[8]);
	Manager.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_nPosY[8]", str);

	str.Format(L"%d", Manager.m_nPosZ[0]);
	Manager.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_nPosZ[0]", str);
	str.Format(L"%d", Manager.m_nPosZ[1]);
	Manager.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_nPosZ[1]", str);
	str.Format(L"%d", Manager.m_nPosZ[2]);
	Manager.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_nPosZ[2]", str);
	str.Format(L"%d", Manager.m_nPosZ[3]);
	Manager.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_nPosZ[3]", str);
	str.Format(L"%d", Manager.m_nPosZ[4]);
	Manager.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_nPosZ[4]", str);
	str.Format(L"%d", Manager.m_nPosZ[5]);
	Manager.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_nPosZ[5]", str);
	str.Format(L"%d", Manager.m_nPosZ[6]);
	Manager.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_nPosZ[6]", str);
	str.Format(L"%d", Manager.m_nPosZ[7]);
	Manager.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_nPosZ[7]", str);
	str.Format(L"%d", Manager.m_nPosZ[8]);
	Manager.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_nPosZ[8]", str);


	str.Format(L"%d", Manager.m_nLockFlag[0]);
	Manager.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_nLockFlag[0]", str);
	str.Format(L"%d", Manager.m_nLockFlag[1]);
	Manager.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_nLockFlag[1]", str);
	str.Format(L"%d", Manager.m_nLockFlag[2]);
	Manager.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_nLockFlag[2]", str);
	str.Format(L"%d", Manager.m_nLockFlag[3]);
	Manager.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_nLockFlag[3]", str);
	str.Format(L"%d", Manager.m_nLockFlag[4]);
	Manager.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_nLockFlag[4]", str);
	str.Format(L"%d", Manager.m_nLockFlag[5]);
	Manager.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_nLockFlag[5]", str);

}





void CSettingDlg::OnBnClickedSetdata()
{
	// TODO: 在此添加控件通知处理程序代码
	int nDis = Manager.m_vCMotor[MOTOR_X].m_nCurPositon;
	nPosX0 = nDis;
	nDis = Manager.m_vCMotor[MOTOR_Y].m_nCurPositon;
	nPosY0 = nDis;
	nDis = Manager.m_vCMotor[MOTOR_Z].m_nCurPositon;
	nPosZ0 = nDis;
	UpdateData(FALSE);

}


void CSettingDlg::OnBnClickedSetdata2()
{
	// TODO: 在此添加控件通知处理程序代码
	int nDis = Manager.m_vCMotor[MOTOR_X].m_nCurPositon;
	nPosX1 = nDis;
	nDis = Manager.m_vCMotor[MOTOR_Y].m_nCurPositon;
	nPosY1 = nDis;
	nDis = Manager.m_vCMotor[MOTOR_Z].m_nCurPositon;
	nPosZ1 = nDis;
	UpdateData(FALSE);
}


void CSettingDlg::OnBnClickedSetdata3()
{
	// TODO: 在此添加控件通知处理程序代码
	int nDis = Manager.m_vCMotor[MOTOR_X].m_nCurPositon;
	nPosX2 = nDis;
	nDis = Manager.m_vCMotor[MOTOR_Y].m_nCurPositon;
	nPosY2 = nDis;
	nDis = Manager.m_vCMotor[MOTOR_Z].m_nCurPositon;
	nPosZ2 = nDis;
	UpdateData(FALSE);
}


void CSettingDlg::OnBnClickedSetdata4()
{
	// TODO: 在此添加控件通知处理程序代码
	int nDis = Manager.m_vCMotor[MOTOR_X].m_nCurPositon;
	nPosX3 = nDis;
	nDis = Manager.m_vCMotor[MOTOR_Y].m_nCurPositon;
	nPosY3 = nDis;
	nDis = Manager.m_vCMotor[MOTOR_Z].m_nCurPositon;
	nPosZ3 = nDis;
	UpdateData(FALSE);
}


void CSettingDlg::OnBnClickedSetdata5()
{
	// TODO: 在此添加控件通知处理程序代码
	int nDis = Manager.m_vCMotor[MOTOR_X].m_nCurPositon;
	nPosX4 = nDis;
	nDis = Manager.m_vCMotor[MOTOR_Y].m_nCurPositon;
	nPosY4 = nDis;
	nDis = Manager.m_vCMotor[MOTOR_Z].m_nCurPositon;
	nPosZ4 = nDis;
	UpdateData(FALSE);
}


void CSettingDlg::OnBnClickedSetdata6()
{
	// TODO: 在此添加控件通知处理程序代码
	int nDis = Manager.m_vCMotor[MOTOR_X].m_nCurPositon;
	nPosX5 = nDis;
	nDis = Manager.m_vCMotor[MOTOR_Y].m_nCurPositon;
	nPosY5 = nDis;
	nDis = Manager.m_vCMotor[MOTOR_Z].m_nCurPositon;
	nPosZ5 = nDis;
	UpdateData(FALSE);
}






void CSettingDlg::OnBnClickedSetdata9()
{
	// TODO: 在此添加控件通知处理程序代码
	int nDis = Manager.m_vCMotor[MOTOR_X].m_nCurPositon;
	PosX8 = nDis;
	nDis = Manager.m_vCMotor[MOTOR_Y].m_nCurPositon;
	PosY8 = nDis;
	nDis = Manager.m_vCMotor[MOTOR_Z].m_nCurPositon;
	PosZ8 = nDis;
	UpdateData(FALSE);
}


void CSettingDlg::OnBnClickedSetdata10()
{
	// TODO: 在此添加控件通知处理程序代码
	int nDis = Manager.m_vCMotor[MOTOR_X].m_nCurPositon;
	nPosX8 = nDis;
	nDis = Manager.m_vCMotor[MOTOR_Y].m_nCurPositon;
	nPosY8 = nDis;
	nDis = Manager.m_vCMotor[MOTOR_Z].m_nCurPositon;
	nPosZ8 = nDis;
	UpdateData(FALSE);
}


void CSettingDlg::OnEnChangeEdit1()
{
	// TODO:  如果该控件是 RICHEDIT 控件，它将不
	// 发送此通知，除非重写 CDialogEx::OnInitDialog()
	// 函数并调用 CRichEditCtrl().SetEventMask()，
	// 同时将 ENM_CHANGE 标志“或”运算到掩码中。

	// TODO:  在此添加控件通知处理程序代码
}
